<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '修改' " :close-on-click-modal='false'
             :close-on-press-escape='false' :fullscreen='true'>
    <el-form :model="dataForm" :rules="dataRule" ref="dataFormRef" @keyup.enter.native="dataFormSubmitHandle()"
             label-width="120px">
             
                <el-form-item label="领用人卡号" prop="cardid">
            <el-input v-model="dataForm.cardid" placeholder="领用人卡号"></el-input>
          </el-form-item>
          <el-form-item label="领用人ID" prop="recipientid">
            <el-input v-model="dataForm.recipientid" placeholder="领用人ID"></el-input>
          </el-form-item>
          <el-form-item label="领用人" prop="recipient">
            <el-input v-model="dataForm.recipient" placeholder="领用人"></el-input>
          </el-form-item>
          <el-form-item label="优先级" prop="priority">
            <el-input v-model="dataForm.priority" placeholder="优先级"></el-input>
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-input v-model="dataForm.status" placeholder="状态"></el-input>
          </el-form-item>
          <el-form-item label="物料编码" prop="sku">
            <el-input v-model="dataForm.sku" placeholder="物料编码"></el-input>
          </el-form-item>
          <el-form-item label="数量" prop="qty">
            <el-input v-model="dataForm.qty" placeholder="数量"></el-input>
          </el-form-item>
          <el-form-item label="仓库" prop="warehouse">
            <el-input v-model="dataForm.warehouse" placeholder="仓库"></el-input>
          </el-form-item>
          <el-form-item label="部门" prop="department">
            <el-input v-model="dataForm.department" placeholder="部门"></el-input>
          </el-form-item>
          <el-form-item label="备用字段1" prop="reserve1">
            <el-input v-model="dataForm.reserve1" placeholder="备用字段1"></el-input>
          </el-form-item>
          <el-form-item label="备用字段2" prop="reserve2">
            <el-input v-model="dataForm.reserve2" placeholder="备用字段2"></el-input>
          </el-form-item>
          <el-form-item label="备用字段3" prop="reserve3">
            <el-input v-model="dataForm.reserve3" placeholder="备用字段3"></el-input>
          </el-form-item>
          <el-form-item label="备用字段4" prop="reserve4">
            <el-input v-model="dataForm.reserve4" placeholder="备用字段4"></el-input>
          </el-form-item>
          <el-form-item label="备用字段5" prop="reserve5">
            <el-input v-model="dataForm.reserve5" placeholder="备用字段5"></el-input>
          </el-form-item>
          <el-form-item label="创建人" prop="adduser">
            <el-input v-model="dataForm.adduser" placeholder="创建人"></el-input>
          </el-form-item>
          <el-form-item label="创建时间" prop="addtime">
            <el-input v-model="dataForm.addtime" placeholder="创建时间"></el-input>
          </el-form-item>
          <el-form-item label="更新人" prop="updatuser">
            <el-input v-model="dataForm.updatuser" placeholder="更新人"></el-input>
          </el-form-item>
          <el-form-item label="更新时间" prop="updatetime">
            <el-input v-model="dataForm.updatetime" placeholder="更新时间"></el-input>
          </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">确定</el-button>
    </template>
  </el-dialog>
</template>

<script>
import {ref, reactive, onMounted, nextTick, computed} from 'vue';
import {getRecipientsforwardById,putRecipientsforward,postRecipientsforward} from "@/network/lswms/recipient/Recipientsforward"
import {ElMessage} from 'element-plus'
import _ from 'lodash'


export default {
  name: "recipientsforwardAddOrUpdate",
  emits: ["refreshDataList"],
  setup(props, {emit}) {
    const visible = ref(false);
    const dataForm = ref({
		          id: '',
          cardid: '',
          recipientid: '',
          recipient: '',
          priority: '',
          status: '',
          sku: '',
          qty: '',
          warehouse: '',
          department: '',
          reserve1: '',
          reserve2: '',
          reserve3: '',
          reserve4: '',
          reserve5: '',
          adduser: '',
          addtime: '',
          updatuser: '',
          updatetime: ''
    });


    const dataRule = reactive({   
                cardid: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          recipientid: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          recipient: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          priority: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          status: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          sku: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          qty: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          warehouse: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          department: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          reserve1: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          reserve2: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          reserve3: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          reserve4: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          reserve5: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          adduser: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          addtime: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          updatuser: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          updatetime: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ]    })

    const dataFormRef = ref(null)

    const init = () => {
      visible.value = true;
      nextTick(function () {
        dataFormRef.value.resetFields();
        if (dataForm.value.id) {
		getrecipientsforwardInfo();
		}
        
      })
    }

	const getrecipientsforwardInfo =()=>{
		getRecipientsforwardById(dataForm.value.id).then(function (res) {
		  if (res.code !== 0) {
		    return ElMessage.error(res.msg);
		  }
		  dataForm.value = _.assignIn({}, dataForm.value, res.data);
		}).catch((err) =>{
		});
	}

    // 表单提交
    const dataFormSubmitHandle = _.debounce(() => {
      dataFormRef.value.validate(function (valid) {
        if (!valid) {
          return false;
        }
		
        let qing = ()=> {
          return !dataForm.value.id ?  postRecipientsforward(dataForm.value) : putRecipientsforward(dataForm.value)
        }
        qing().then(function (res) {
          if (res.code !== 0) {
            return ElMessage.error(res.msg);
          }
          ElMessage({
            message: '操作成功',
            type: 'success',
            duration: 500,
            onClose: function () {
              visible.value = false
              emit('refreshDataList')
            }
          })
        }).catch(function () {
        });

      })
    }, 1000, {'leading': true, 'trailing': false})

    return {
      visible,
      dataForm,
      dataRule,
      init,
      dataFormSubmitHandle,
      dataFormRef

    }
  },


}
</script>

<style scoped>

</style>